import Vue from 'vue'
import { setForm, getForm, setImgSrc, getImgSrc, setContent, getContent } from '@/utils/course'

const resetForm = {
  username: '',
  password: '',
  password2: '',
  newPassword: '',
  roleId: '',
  name: '',
  phone: '',
  status: '',
  headImg: '',
  telephone: '',
  fax: '',
  email: ''
}
const sysUser = {
  state: {
    sysUserForm: {
      username: '',
      password: '',
      password2: '',
      newPassword: '',
      roleId: '',
      name: '',
      phone: '',
      status: '',
      headImg: '',
      telephone: '',
      fax: '',
      email: ''
    }
  },

  mutations: {
    SET_USER_FORM: (state, sysUserForm) => {
      state.sysUserForm = sysUserForm
    },
    SET_HEADIMG: (state, object) => {
      const newObject = Object.assign({}, state.sysUserForm, object);
      state.sysUserForm = newObject
    },
    SET_USER_FORM_RESET: (state, ruleForm) => {
      const data = Object.assign({}, ruleForm);
      state.sysUserForm = null;
      state.sysUserForm = data
    }
  },

  actions: {
    addListenerUser({ commit }, form) {
      return new Promise((resolve) => {
        commit('SET_USER_FORM', form);
        resolve();
      })
    },

    addListenerHeadImg({ commit }, form) {
      return new Promise((resolve) => {
        commit('SET_HEADIMG', form);
        resolve();
      })
    },

    resetFunc({ commit }) {
      return new Promise((resolve) => {
        commit('SET_USER_FORM_RESET', resetForm);
        resolve();
      })
    }
  }
};

export default sysUser;
